package com.mystudy.selfCheck;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 周志龙
 * @Email 15216876513@163.com
 * @Date on 2019/7/27 22:30
 * @Description
 */
public class fffff {
    private static final Logger LOGGER = LoggerFactory.getLogger(fffff.class);

    public int largestUniqueNumber(int[] A) {
        int[] arr = new int[1000];
        for (int i = 0; i < A.length; i++) {
            arr[A[i]]++;
        }
        int MAX = -1;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 1) {
                if (i > MAX) {
                    MAX = i;
                }
            }
        }
        return MAX;
    }

    @Test
    public void test() {
        boolean armstrong = isArmstrong(153);
        LOGGER.debug("armstrong = [{}]", armstrong);
    }

    public boolean isArmstrong(int N) {
        String s = String.valueOf(N);
        int length = s.length();
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            String value = String.valueOf(s.charAt(i));
            Integer inte = Integer.valueOf(value);
            sum = (int) (sum + Math.pow(inte, length));
        }
        return sum == N;

    }


    @Test
    public void testtri() {
        int tribonacci = tribonacci(33);
        LOGGER.debug("tribonacci = [{}]", tribonacci);
    }

    public int tribonacci(int n) {
        switch (n) {
            case 0:
                return 0;
            case 1:
                return 1;
            case 2:
                return 1;
            case 3:
                return 2;
            case 4:
                return 4;
            case 5:
                return 7;
            case 6:
                return 13;
            case 7:
                return 24;
            case 8:
                return 44;
        }

        return tribonacci(n - 3) + tribonacci(n - 2) + tribonacci(n - 1);
    }


    @Test
    public void testAlpha(){
        String leet = alphabetBoardPath("leet");
        LOGGER.debug("leet = [{}]",leet);

    }

    public String alphabetBoardPath(String target) {
        char curIndex = 'a';
        String route = "";
        for (int i = 0; i < target.length(); i++) {
            char c = target.charAt(i);
            int level = getLevel(c);
            int curLevel = getLevel(curIndex);
            int m = curLevel - level;
            if (m != 0) {
                if (curLevel > level) {
                    route += "U";
                } else {
                    route += "D";
                }
            } else {
                int n = curIndex - c;
                if (n != 0) {
                    if (curIndex > c) {
                        for (int j = 0; j < n; j++) {
                            route += "L";
                        }
                    } else {
                        for (int j = 0; j < n; j++) {
                            route += "R";
                        }
                    }
                    curIndex = c;
                } else {
                    route += "!";
                }
            }
        }
        return route;
    }


    private int getLevel(char c) {
        if (c >= 'a' && c <= 'e') {
            return 1;
        } else if (c >= 'f' && c <= 'j') {
            return 2;
        } else if (c >= 'k' && c <= 'o') {
            return 3;
        } else if (c >= 'p' && c <= 't') {
            return 4;
        } else if (c >= 'u' && c <= 'v') {
            return 5;
        } else {
            return 6;
        }
    }


    @Test
    public void long2String(){
        List<Long> l = new ArrayList<>();
        l.add(234L);
        l.add(23234234L);
        LOGGER.debug("l = {}",l.toString().replace("[","").replace("]",""));
    }

}
